home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue46 / packages / DinoSource.Zip / NonFlatButtons.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-10-29  |  4.0 KB  |  155 lines

  1. unit NonFlatButtons;
  2.  
  3. {$ifdef Ver100} { Delphi 3.0x }
  4.   {$define DelphiLessThan4}
  5. {$endif}
  6. {$ifdef Ver110} { C++ Builder 3.0x }
  7.   {$define DelphiLessThan4}
  8. {$endif}
  9.  
  10. interface
  11.  
  12. procedure Register;
  13.  
  14. implementation
  15.  
  16. uses
  17.   CommonStuff, ExtCtrls, Buttons, Menus, Forms, Controls,
  18.   SysUtils, Dialogs, ComCtrls;
  19.  
  20. type
  21.   TNonFlatButtons = class(TObject)
  22.   private
  23.   {$ifdef DelphiLessThan4}
  24.     FSpeedBar: TPanel;
  25.   {$else}
  26.     FSpeedBars: array[1..4] of TToolBar;
  27.   {$endif}
  28.     FSpeedBarPopup: TPopupMenu;
  29.     FSpeedBarFlat: TMenuItem;
  30.   protected
  31.     procedure SetFlatButtons(Value: Boolean);
  32.     procedure DoFlatButtons(Sender: TObject);
  33.   public
  34.     constructor Create;
  35.     destructor Destroy; override;
  36.     procedure Setup;
  37.     procedure TidyUp;
  38.   end;
  39.  
  40. resourcestring
  41.   SFlat = '&Flat Buttons';
  42.  
  43. const
  44. {$ifdef DelphiLessThan4}
  45.   SSpeedBarPopup = 'SpeedbarMenu'; //Speed bar's TPopupMenu
  46.   SSpeedBar = 'SpeedPanel'; //Speed bar component
  47. {$else}
  48.   SSpeedBarPopup = 'ToolBarsPopup'; //Speed bar's TPopupMenu
  49.   SStandardBar = 'StandardToolBar';
  50.   SViewBar = 'ViewToolBar';
  51.   SCustomBar = 'CustomToolBar';
  52.   SDebugBar = 'DebugToolBar';
  53. {$endif}
  54.   SRegFlatSpeedBar = 'Flat Speedbar'; //Registry string
  55.  
  56. constructor TNonFlatButtons.Create;
  57. begin
  58.   inherited Create;
  59. end;
  60.  
  61. destructor TNonFlatButtons.Destroy;
  62. begin
  63.   TidyUp;
  64.   inherited Destroy
  65. end;
  66.  
  67. procedure TNonFlatButtons.Setup;
  68. begin
  69.   //Make sure there is an options menu - bear in mind
  70.   //that the other options code might not be being used
  71.   Stuff.AddOptionsItem;
  72.   //Find speed bar(s)
  73. {$ifdef DelphiLessThan4}
  74.   FSpeedBar := GetComponent(Application.MainForm, SSpeedBar, SGenericError + SSpeedBar) as TPanel;
  75. {$else}
  76.   FSpeedBars[1] := GetComponent(Application.MainForm, SStandardBar, SGenericError + SStandardBar) as TToolBar;
  77.   FSpeedBars[2] := GetComponent(Application.MainForm, SViewBar,     SGenericError + SViewBar) as TToolBar;
  78.   FSpeedBars[3] := GetComponent(Application.MainForm, SCustomBar,   SGenericError + SCustomBar) as TToolBar;
  79.   FSpeedBars[4] := GetComponent(Application.MainForm, SDebugBar,    SGenericError + SDebugBar) as TToolBar;
  80. {$endif}
  81.   //Find speed bar's popup menu
  82.   FSpeedBarPopup := GetComponent(Application.MainForm, SSpeedBarPopup, SGenericError + SSpeedBarPopup) as TPopupMenu;
  83.   //Set up option menu item
  84.   FSpeedBarFlat := NewItem(SFlat, 0,
  85.     Stuff.Ini.ReadBool(SRegSection, SRegFlatSpeedBar,
  86.     {$ifdef DelphiLessThan4}
  87.       (FSpeedBar.Controls[0] as TSpeedButton).Flat),
  88.     {$else}
  89.       FSpeedBars[1].Flat),
  90.     {$endif}
  91.     True, DoFlatButtons, 0, '');
  92. {$ifdef DelphiLessThan4}
  93.   FSpeedBarPopup.Items.Insert(1, FSpeedBarFlat);
  94. {$else}
  95.   Stuff.FOptions.Add(FSpeedBarFlat);
  96. {$endif}
  97.   //Set the speedbar properties as dictated by registry
  98.   SetFlatButtons(FSpeedBarFlat.Checked);
  99. end;
  100.  
  101. procedure TNonFlatButtons.TidyUp;
  102. begin
  103.   //Get rid of option menu item
  104.   FSpeedBarFlat.Free;
  105.   //Restore IDE original state
  106.   SetFlatButtons(True);
  107.   //Save option information
  108.   Stuff.Ini.WriteBool(SRegSection, SRegFlatSpeedBar, FSpeedBarFlat.Checked);
  109. end;
  110.  
  111. procedure TNonFlatButtons.SetFlatButtons(Value: Boolean);
  112. var
  113.   Loop: Integer;
  114. begin
  115.   //Set Flat option as appropriate
  116. {$ifndef DelphiLessThan4}
  117.   for Loop:= Low(FSpeedBars) to High(FSpeedBars) do
  118.     FSpeedBars[Loop].Flat := Value
  119. {$else}
  120.   with FSpeedBar do
  121.     for Loop := 0 to ControlCount - 1 do
  122.       if Controls[Loop] is TSpeedButton then
  123.         TSpeedButton(Controls[Loop]).Flat := Value
  124. {$endif}
  125. end;
  126.  
  127. procedure TNonFlatButtons.DoFlatButtons(Sender: TObject);
  128. begin
  129.   //Toggle Flat option
  130.   with (Sender as TMenuItem) do
  131.   begin
  132.     Checked := not Checked;
  133.     SetFlatButtons(Checked)
  134.   end
  135. end;
  136.  
  137. var
  138.   NonFlatButtonsObject: TNonFlatButtons;
  139.  
  140. procedure Register;
  141. begin
  142.   NonFlatButtonsObject.Setup
  143. end;
  144.  
  145. initialization
  146.   try
  147.     NonFlatButtonsObject := TNonFlatButtons.Create
  148.   except
  149.     on E: Exception do
  150.       ShowMessage(SSetupError + ': ' + E.Message)
  151.   end
  152. finalization
  153.   NonFlatButtonsObject.Free
  154. end.
  155.